﻿
    <div>
        <button type="button" class="layui-btn layui-btn-sm" data-type="export"><i class="layui-icon">&#xe674;导出</i></button>
        <button type="button" class="layui-btn layui-btn-sm  layui-btn-danger" data-type="clear"><i class="layui-icon">&#xe640;清空</i></button>
        <button type="button" class="layui-btn layui-btn-sm  layui-btn-normal" data-type="reload"><i class="layui-icon">&#xe666;刷新</i></button>
    </div>

<table id="datalist" lay-filter="datalist"></table>
<script type="text/html" id="indexTpl">
    {{d.LAY_INDEX}}@*//此为自动序号下标从1开始，第二页从第一页的末尾递增。即如果每页10条，第二页第一条显示11*@
</script>
@section Scripts{
    <script>
        layui.use(['table','layer','form'], function () {
            var table = layui.table;
            var layer = layui.layer;
            var form = layui.form;
            var $ = layui.jquery
            var queryString = getRequest();

            var fiels = '@string.Join(",",ViewBag.Fields)'.split(',');
            var cols = [{ title: '序号', width: 60, toolbar: '#indexTpl'}];
            $.each(fiels, function () {
                var _this = this;
                cols.push({ field: _this, title: _this})
            })
            //第一个实例
            table.render({
                elem: '#datalist'
                , height: 'full-40'
                , url: '@Url.Action("ResultList","CollectInfoConfig")?configId='+queryString.configId+'&analyzerFullName='+queryString.analyzerFullName //数据接口
                , page: true //开启分页
                , cols: [cols]
            });


            //事件
            var active = {
                export: function () {
                    window.top.open( '@Url.Action("Export","CollectInfoConfig")?configId='+queryString.configId+'&analyzerFullName='+queryString.analyzerFullName )
                }
                , clear: function () {
                    layer.confirm('是否确认清空记录?', function(index){
                        //do something
                        //提交数据到后台
                        $.post('@Url.Action("Clear","CollectInfoConfig")?configId='+queryString.configId+'&analyzerFullName='+queryString.analyzerFullName, {}, function (res) {
                            if (res.code == 0) {
                                table.reload('datalist'); //数据刷新
                                layer.close(index); //关闭弹层
                            }
                            else {
                                layer.alert(res.msg);
                            }
                        });
                        layer.close(index);
                    });
                },
                reload: function () {
                    location.reload();
                }
            }
            //外部事件监听
            $('.layui-btn').on('click', function(){
              var type = $(this).data('type');
              active[type] ? active[type].call(this) : '';
            });

            

        });
    </script>
}
